<template>
	<view class="container">
		<input type="text" v-model="userInfo.username" placeholder="请填写用户名~">
		<view class="btn" @click="submit">确定</view>
	</view>
</template>

<script>
	import {
		loading,
		loaded,
		tip
	} from '../../../utils/tip.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				name: '最帅'
			};
		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			submit() {
				if (!this.userInfo.username) {
					tip({
						title: '用户名不能为空'
					})
					return
				}
				let params = {
					username: this.userInfo.username
				}
				loading()
				this.$service.common.personUpdate(params).then((res) => {
					this.$store.dispatch('getUserInfo')
					loaded()
					uni.navigateBack({
						delta: 1
					})
				}).catch((err) => {
					loaded()
					tip({
						title: err
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100vw;
		height: 100vh;
		background-color: white;
		padding: 0 24rpx;
		padding-top: 50rpx;
	}

	input {
		border-bottom: 2rpx solid #F2F2F2;
		padding: 12rpx 0;
	}

	.btn {
		width: 342rpx;
		height: 72rpx;
		border-radius: 42rpx;
		background-color: $main-color;
		position: fixed;
		bottom: 96rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
		text-align: center;
		line-height: 72rpx;
		color: white;
		font-size: 28rpx;
	}
</style>
